package com.douhulu.bytedance.open.util.json;

import com.douhulu.bytedance.common.util.json.GsonHelper;
import com.douhulu.bytedance.open.bean.ByteOpenAccessToken;
import com.douhulu.bytedance.open.bean.ByteOpenClientToken;
import com.google.gson.*;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Type;

/**
 * <h2> 奕泽云 -  </h2>
 *
 * @Author: 奕泽云 - 曾庆雷
 * @Email: 75881401@qq.com
 * @Since: 2022/5/4  19:31
 * CopyRight：山西威斯汀文化传播有限公司
 */
@Slf4j
public class ByteOpenClientTokenGsonAdapter implements JsonDeserializer<ByteOpenClientToken> {

    @Override
    public ByteOpenClientToken deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
        ByteOpenClientToken clientToken = new ByteOpenClientToken();
        JsonObject jsonObject = jsonElement.getAsJsonObject().getAsJsonObject("data");
        clientToken.setAccessToken(GsonHelper.getString(jsonObject, "access_token"));
        clientToken.setExpiresIn(GsonHelper.getInteger(jsonObject, "error_code"));
        clientToken.setDescription(GsonHelper.getString(jsonObject, "description"));
        clientToken.setExpiresIn(GsonHelper.getInteger(jsonObject, "expires_in"));
        return clientToken;
    }
}
